<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:6}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ssyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:6}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:12}" style="text-align:center">
            <a-button type="primary" @click="handleAdd">新增</a-button>
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleBatchDelete">批量删除</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
      :scroll="{ x: 1500 }"
    >
    <template slot="action" slot-scope="text,record">
        <a @click="handleEdit(record)">修改</a>
        <a @click="handleDelete(record)">删除</a>
      </template>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>

      <!-- 审核 -->
      <departments-generate-add :departmentsGenerateAddVisible="departmentsGenerateAddVisible" @close="handleAddClose" @success="handleAddSuccess" ></departments-generate-add>
      <!-- 修改 -->
      <departments-generate-edit :info="departmentsGenerateEditData" :departmentsGenerateEditVisible="departmentsGenerateEditVisible" @close="handleEditClose" @success="handleEditSuccess" ></departments-generate-edit>

    </a-card>
</div>
</template>

<script>
// import moment from 'moment'
import DepartmentsGenerateAdd from './departmentsGenerateAdd'
import DepartmentsGenerateEdit from './departmentsGenerateEdit'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    DepartmentsGenerateAdd,
    DepartmentsGenerateEdit
  },
  data () {
    return {
      departmentsGenerateAddVisible: false,
      departmentsGenerateEditVisible: false,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx'
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '院系',
          dataIndex: 'yx'
        },
        {
          title: '专业',
          dataIndex: 'zy'
        },
        {
          title: '笔试时间、地点',
          dataIndex: 'bssjdd'
        },
        {
          title: '面试时间、地点',
          dataIndex: 'mssjdd'
        },
        {
          title: '联系人',
          dataIndex: 'lxr'
        },
        {
          title: '联系方式',
          dataIndex: 'lxfs'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      },
      selectMenu: {
        yx: [] // 院系
      },
      departmentsGenerateEditData: {}
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
    },
    // 加载数据
    loadData () {
      return new Promise(resolve => { resolve() }).then(res => {
        this.data = [{
          yx: '电子院',
          zy: '计算机',
          bssjdd: '2018-8-9 南京',
          mssjdd: '2018-8-9 东京',
          lxr: '林心如',
          lxfs: '158506900124',
          key: 1
        }, {
          yx: '电子院',
          zy: '计算机',
          bssjdd: '2018-8-9 南京',
          mssjdd: '2018-8-9 东京',
          lxr: '林心如',
          lxfs: '158506900124',
          key: 12
        }, {
          yx: '电子院',
          zy: '计算机',
          bssjdd: '2018-8-9 南京',
          mssjdd: '2018-8-9 东京',
          lxr: '林心如',
          lxfs: '158506900124',
          key: 18
        }]
      })
    },
    // 导出
    handleExport () {
      console.log('导出')
    },
    // 添加
    handleAdd () {
      this.departmentsGenerateAddVisible = true
    },
    // 关闭添加
    handleAddClose () {
      this.departmentsGenerateAddVisible = false
    },
    // 添加成功返回
    handleAddSuccess () {
      this.departmentsGenerateAddVisible = false
    },
    // 修改
    handleEdit (data) {
      this.departmentsGenerateEditData = {
        yx: '',
        zt: '',
        mssjdd: '2018-5-5 东京',
        bssjdd: '1094728',
        lxr: '联系人',
        lxfs: '167965297'
      }
      this.departmentsGenerateEditVisible = true
    },
    // 关闭修改
    handleEditClose () {
      this.departmentsGenerateEditVisible = false
    },
    // 修改成功返回
    handleEditSuccess () {
      this.departmentsGenerateEditVisible = false
    },
    // 删除
    handleDelete () {},
    // 删除
    handleBatchDelete () {}
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
